package com.jyc.service;

import com.jyc.entity.shop.Item;
import com.jyc.mapper.shop.ItemCategoryMapper;
import com.jyc.mapper.shop.ItemMapper;
import com.jyc.mapper.shop.ItemOrderMapper;
import com.jyc.vo.ck.ShebeiguihaiVO;
import com.jyc.vo.shop.ItemChartVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;

@Service
@Transactional
public class ShopService {
    @Autowired(required = false)
    private ItemMapper itemMapper;
    @Autowired(required = false)
    private ItemCategoryMapper itemCategoryMapper;
    @Autowired(required = false)
    private ItemOrderMapper itemOrderMapper;

    public List<Item> getItemList() {
        return itemMapper.selectByExample(null);
    }

    public List<ItemChartVO> showPie() {
        return itemMapper.showPie();
    }

    public List<ItemChartVO> showPillar() {
        return itemMapper.showPillar();
    }

    public List<ItemChartVO> showLine() {
        return itemMapper.showLine();
    }


    public Set<List> show3DByNum() {
        Set<List> dataSet = new LinkedHashSet<>();
        List<String> times = itemMapper.selectTime();
        for (String time : times) {
            if (dataSet.size() == 0) {
                List first = new ArrayList();
                first.add("售出日期");
                first.add("商品类型");
                first.add("数量");
                dataSet.add(first);
            }
            List<ItemChartVO> itemChartVOS = itemMapper.showOneInfoByTime(time);
            for (ItemChartVO itemChartVO : itemChartVOS) {
                List tempList= new ArrayList();
                tempList.add(time);
                tempList.add(itemChartVO.getName());
                tempList.add(itemChartVO.getTotalnum());
                dataSet.add(tempList);
            }
        }
        return dataSet;
    }

    public Set<List> show3DByPrice() {
        Set<List> dataSet = new LinkedHashSet<>();
        List<String> times = itemMapper.selectTime();
        for (String time : times) {
            if (dataSet.size() == 0) {
                List first = new ArrayList();
                first.add("售出日期");
                first.add("商品类型");
                first.add("总金额");
                dataSet.add(first);
            }
            List<ItemChartVO> itemChartVOS = itemMapper.showTotalPriceByTime(time);
            for (ItemChartVO itemChartVO : itemChartVOS) {
                List tempList= new ArrayList();
                tempList.add(time);
                tempList.add(itemChartVO.getName());
                tempList.add(itemChartVO.getTotalprice());
                dataSet.add(tempList);
            }
        }
        return dataSet;
    }
}
